
function quickSort(arr: number[]) {
    return quick(arr, 0, arr.length - 1);
}

function quick(arr: number[], left: number, right: number) {
    if (arr.length > 1) {
        let index = partition(arr, left, right);
        if (left < index - 1) {
            quick(arr, left, index - 1);
        }
        if (index < right) {
            quick(arr, index, right);
        }
    }
    return arr;
}

function partition(arr: number[], left, right) {

    let povit = arr[left];
    let i = left, j = right;

    while (i <= j) {
        while (arr[i] < povit) {
            i++;
        }

        while (arr[j] > povit) {
            j--;
        }
        if (i <= j) {
            [arr[i], arr[j]] = [arr[j], arr[i]];
            i++;
            j--;
        }
    }

    return i;
}
let arr = [3, 5, 1, 6, 4, 7, 2];
arr=quickSort(arr);
console.log(arr)